package com.limm.cloud01.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.limm.cloud01.entity.Dept;
import com.limm.cloud01.service.impl.DeptService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author LiMM
 * @since 2021-09-09
 */
@RestController
@RequestMapping("/cloud/dept")
public class DeptController {


    @Autowired
    DeptService service;


    @GetMapping("/get/{id}")
    @HystrixCommand(fallbackMethod = "hystrixDept")
    public Dept get(@PathVariable Long id){

        final Dept one = service.getOne(new QueryWrapper<Dept>().eq("dept_no", id));
        if (one==null){
           throw  new RuntimeException("id-->"+id+": 不存在该id");
        }
        return one;
    }

    public Dept hystrixDept(@PathVariable Long id){
        return new Dept().setDeptName("\"id-->\"+id+\": 不存在该id\"")
                .setDeptNo(id)
                .setDbResource("this dept no database in MySQL");
    }



}

